#include "spline_counter.h"
#include <cassert>
using namespace math;

SplineCounter::SplineCounter(float	CountLimit) :
	Counter(CountLimit)
{
}

SplineCounter::~SplineCounter()
{

}

#define	B1(t)		(t*t)
#define	B2(t)		(2*t*(1-t))
#define	B3(t)		((1-t)*(1-t))
float	SplineCounter::GetSpline(float Progress)
{
	math::Vec2	Res;
	UTIL_CLAMP(Progress, 0, 1);
/*D3DXVec2CatmullRom(&Res,&m_SplineA[0],&m_SplineA[1], &m_SplineA[2],&m_SplineA[3], Progress);
*/
	float	count = Progress;

	Res.x = m_SplineA[0].x*B1(count) + m_SplineA[1].x*B2(count) + m_SplineA[2].x*B2(count);
	Res.y = m_SplineA[0].y*B1(count) + m_SplineA[1].y*B2(count) + m_SplineA[2].y*B2(count);
	return Res.y;
}

float	SplineCounter::GetSpline()
{
	return GetSpline(GetProgress());
}

void	SplineCounter::SetSplineData(int Index, float Val)
{
	assert(Index >= 0 && Index < SPLINE_C);

	m_SplineA[Index].x = float(Index) / float(SPLINE_C);
	m_SplineA[Index].y = Val;
}
